﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Problem22
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> allNames = new List<string>(5163);
            foreach (string name in File.ReadAllText("names.txt").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                allNames.Add(name.Trim('\"'));
            }

            allNames.Sort();

            long sum = 0;
            int index = 1;
            foreach (string name in allNames)
            {
                int nameSum = 0;
                foreach (char c in name)
                {
                    nameSum += c - 'A' + 1;
                }

                sum += (nameSum * index++);
            }

            Console.WriteLine(sum);
            Console.ReadKey();
        }
    }
}
